package net.lainiao.morethread.Chapter4.demo6;

import java.util.Date;
import java.util.concurrent.*;

/**
 * Created by Administrator on 2017/3/3.
 */
public class Main {
    public static void main(String[] args) {
        ScheduledThreadPoolExecutor executorService = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1);
        System.out.println("Main:Starting at "+new Date());
        for (int i = 0; i < 5; i++) {
            Task task=new Task("Task"+i);
            executorService.schedule(task,(i+1), TimeUnit.SECONDS);
        }
//        try {
//            Thread.sleep(2000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        executorService.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
        executorService.shutdown();
        try {
            executorService.awaitTermination(1,TimeUnit.DAYS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Main: Ends at :"+new Date());

    }
}
